/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Games;

import Client.Command;
import java.awt.Canvas;
import Client.GraphicPiece;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Brandon
 */
public class TicTacToe extends AbstractFunctions {
    
    private BoardCanvas canvas;
    private GamesModel gamesModel;
    private GamesController gamesController;
 
    private int rows = 3;
    private int cols = 3;
    
    public TicTacToe(String player1, String selectedGame) {
        //Initialize the board
        board = new Board(cols,rows);
        gamesModel = new GamesModel(board,selectedGame);
        gamesModel.setPlayerOne(player1);
        setGameModel(gamesModel);
        GameFrame().getPlayerView().setPlayerOne(player1);
        GameFrame().setGameModel(gamesModel);
        gamesController = new GamesController(this, gamesModel, GameFrame());
        
        //Initialize the Canvas where the board is drawn on.
        canvas = new BoardCanvas(GameFrame().getBoardView().getWidth(),GameFrame().getBoardView().getHeight(),cols,rows, gamesModel,gamesController);
        GameFrame().getBoardView().add(canvas);
        gamesController.setBoardCanvas(canvas);
    }
    
    public Canvas getCanvas() {
        return canvas;
    }
    
    public GamesModel getGamesModel(){
    	return gamesModel;
    }
    

	@Override
	public void start() {
	}

	@Override
	public void initiateBoard(boolean weBegin) {
	}

	@Override
	public void updateBoard(String player, int move) {
	}

	@Override
	public GraphicPiece getGraphicPiece(int player, int col, int row, int width, int height) {
		if (player==0) {
			return new XPiece(col, row, width, height);
		} else {
			return new CirclePiece(col, row, width, height);
		}
	}
    @Override    
    public void chooseMove(int currentPlayer) {
        Best best = TicTacToeAI.chooseMove(currentPlayer, board.getBoard());
        int move = (cols*best.col)+best.row;
        System.out.println("MOVE");
        Command.move(move);
    }

	@Override
	public void opponentMove(int move) {
		// TODO Auto-generated method stub
	}
}
